<template>
  <div>
<!-- 面包屑 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>订单管理</el-breadcrumb-item>
        <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
<!-- 卡片 -->
    <el-card>
        <!-- 搜索区域 -->
        <el-row>
            <el-col :span='10'>
                <el-input placeholder="请输入内容" v-model="queryorder.query" clearable @clear='getorderlist'>
                    <el-button slot="append" icon="el-icon-search" @click="getorderlist"></el-button>
                </el-input>
            </el-col>
        </el-row>
        <!-- 表格区域 -->
        <el-table :data="orderlist" style="width: 100%" stripe border>
            <el-table-column type="index"></el-table-column>
            <el-table-column prop="order_number" label="订单编号"></el-table-column>
            <el-table-column prop="order_price" label="订单价格" width="100px"></el-table-column>
            <el-table-column prop="pay_status" label="是否支付" width="100px">
                <template slot-scope="scope">
                    <el-tag v-if='scope.row.pay_status==="1"'>已付款</el-tag>
                    <el-tag v-else type="danger">未付款</el-tag>
                </template>
            </el-table-column>
            <el-table-column prop="is_send" label="是否发货" width="100px"></el-table-column>
            <el-table-column prop="create_time" label="下单时间">
                <template slot-scope="scope">
                    {{scope.row.create_time | dataformat}}
                </template>           
            </el-table-column>
            <el-table-column label="操作" width="130px">
                <template slot-scope="scope">
                    <el-tooltip class="item" effect="dark" content="修改地址" placement="top">
                        <el-button size="mini" type="primary" icon="el-icon-edit" @click="editlocation(scope.row.order_id)"></el-button>
                    </el-tooltip>
                    <el-tooltip class="item" effect="dark" content="物流进度" placement="top">
                        <el-button size="mini" type="success" icon="el-icon-location" @click="showprogressbox(scope.row.order_id)"></el-button>
                    </el-tooltip>
                </template>
            </el-table-column>
        </el-table>

        <!-- 分页器 -->
        <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryorder.pagenum"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="queryorder.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total" background>
        </el-pagination>
    </el-card>

    <!-- 修改地址弹出框 -->
    <el-dialog
    title="修改地址"
    :visible.sync="adddialogVisible"
    width="50%"
    @close='editclose'>
        
        <!-- 表单区域 -->
        <el-form :model="editruleForm" :rules="editrules" ref="editruleFormref" label-width="100px" class="demo-ruleForm">
            <!-- 级联选择框 -->
            <el-form-item label="省市区/县" prop="editress1">
                  <el-cascader
                    v-model="editruleForm.editress1"
                    :options="cityDate">
                </el-cascader>
            </el-form-item>
            <!-- 详细地址 -->
            <el-form-item label="详细地址" prop="editress2">
                <el-input v-model="editruleForm.editress2"></el-input>
            </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button @click="adddialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="adddialogVisible = false">确 定</el-button>
        </span>
    </el-dialog>

    <!-- 物流进度弹出框 -->
    <el-dialog
    title="物流进度"
    :visible.sync="showdialogVisible"
    width="50%"
    >
        <!-- 时间线 -->
          <el-timeline :reverse='false'>
            <el-timeline-item
            v-for="(activity, index) in progressinfo"
            :key="index"
            :timestamp="activity.time">
            {{activity.context}}
            </el-timeline-item>
        </el-timeline>
        <span slot="footer" class="dialog-footer">
            <el-button @click="showdialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="showdialogVisible = false">确 定</el-button>
        </span>
    </el-dialog>
  </div>
</template>

<script>
// 导入城市js文件
import cityDate from './citydata'

export default {
  name: 'order',
  data(){
      return{
        //   订单列表
        orderlist:[],
        //   订单查询参数
        queryorder:{
            query:'',//查询参数
            pagenum:1,//当前页码
            pagesize:10,//每页显示条数
            user_id:'',//用户id
            pay_status:'',//支付状态
            is_send:'',//是否发货
            order_fapiao_title:'',//[’个人‘，’公司‘]
            order_fapiao_company:'',//公司名称
            order_fapiao_content:'',//发票内容
            consignee_addr:'',//发货地址
        },
        total:0,//总条数
        // 修改地址弹出框显示隐藏
        adddialogVisible:false,
        // 修改地址信息对象
        editruleForm:{
            editress1:[],
            editress2:'',
        },
        // 修改地址验证规则
        editrules:{
            editress1:[
                {required:true,message:'请输入省市区',trigger:'blur'},
            ],
            editress2:[
                {required:true,message:'请输入详细地址',trigger:'blur'},
            ]
        },
        // 级联地址导入
        cityDate:cityDate,
        // 点击物流进度按钮显示隐藏对话框
        showdialogVisible:false,
        // 物流进度
        progressinfo: [
    {
      "time": "2018-05-10 09:39:00",
      "ftime": "2018-05-10 09:39:00",
      "context": "已签收,感谢使用顺丰,期待再次为您服务",
      "location": ""
    },
    {
      "time": "2018-05-10 08:23:00",
      "ftime": "2018-05-10 08:23:00",
      "context": "[北京市]北京海淀育新小区营业点派件员 顺丰速运 95338正在为您派件",
      "location": ""
    },
    {
      "time": "2018-05-10 07:32:00",
      "ftime": "2018-05-10 07:32:00",
      "context": "快件到达 [北京海淀育新小区营业点]",
      "location": ""
    },
    {
      "time": "2018-05-10 02:03:00",
      "ftime": "2018-05-10 02:03:00",
      "context": "快件在[北京顺义集散中心]已装车,准备发往 [北京海淀育新小区营业点]",
      "location": ""
    },
    {
      "time": "2018-05-09 23:05:00",
      "ftime": "2018-05-09 23:05:00",
      "context": "快件到达 [北京顺义集散中心]",
      "location": ""
    },
    {
      "time": "2018-05-09 21:21:00",
      "ftime": "2018-05-09 21:21:00",
      "context": "快件在[北京宝胜营业点]已装车,准备发往 [北京顺义集散中心]",
      "location": ""
    },
    {
      "time": "2018-05-09 13:07:00",
      "ftime": "2018-05-09 13:07:00",
      "context": "顺丰速运 已收取快件",
      "location": ""
    },
    {
      "time": "2018-05-09 12:25:03",
      "ftime": "2018-05-09 12:25:03",
      "context": "卖家发货",
      "location": ""
    },
    {
      "time": "2018-05-09 12:22:24",
      "ftime": "2018-05-09 12:22:24",
      "context": "您的订单将由HLA（北京海淀区清河中街店）门店安排发货。",
      "location": ""
    },
    {
      "time": "2018-05-08 21:36:04",
      "ftime": "2018-05-08 21:36:04",
      "context": "商品已经下单",
      "location": ""
    }
  ],
      }
  },
  created(){
      this.getorderlist()
  },
  methods:{
    //   获取订单列表
      async getorderlist(){
          const {data:res}=await this.$axios.get('orders',{params:this.queryorder})
          if(res.meta.status!==200) return this.$message.error('获取订单列表失败')
          this.total=res.data.total
          this.orderlist=res.data.goods
      },
    //   监听每页的数量发生改变时触发
    handleSizeChange(newsize){
        this.queryorder.pagesize=newsize
        this.getorderlist()
    },
    // 监听当前显示页发生变化时触发
    handleCurrentChange(newpagenum){
        this.queryorder.pagenum=newpagenum
        this.getorderlist()
    },
    // 点击修改地址弹出框按钮，展示
    editlocation(id){
        // this.$axios.put('orders/'+id).thrn(res=>{
        //     if(res.data.meta.status!==200) return this.$message.error('获取订单失败')
        //     console.log(res.data.data)
        // })
        this.adddialogVisible=true
    },
    // 监控修改地址的关闭事件，重置表单
    editclose(){
        this.$refs.editruleFormref.resetFields()
    },
    // 点击物流进度弹出框
    showprogressbox(id){
        // this.$axios.get('/kuaidi/1106975712662').then(res=>{
        //     if(res.data.meta.status!==200) return this.$message.error('获取物流进度失败')
        //     this.progressinfo=res.data.data
        //     this.$message.success('获取物流进度成功')
        //     console.log(this.progressinfo)
        // })
        this.showdialogVisible=true
        console.log(this.progressinfo)
    }
  }
}
</script>

<style lang="less" scoped>
.el-cascader{
    width: 100%;
}
</style>
